Skip to content

Engine Setup ​

The plugin stores an 8-bit blend ID per pixel in the GBuffer. The launcher version of Unreal has no free GBuffer channel, so the plugin shares one, and patches the engine shaders to make that work. The two built-in ways of doing this are called encodings. For which one to pick, see GBuffer Encodings.

GBuffer AO encoding ​

The default encoding uses the material Ambient Occlusion channel to send data between the meshes in the scene and the shader through the GBuffer.

  • The MeshBlend_Activator material function outputs the blend ID to the material AO pin, which is stored in the GBuffer like normal AO.
  • The shader patches stop Unreal's lighting from reading that channel as AO.
  • r.Lumen.ScreenProbeGather.MaterialAO=0 stops Lumen from reading it.
  • Static lighting stores baked lighting in the same channel, so r.AllowStaticLighting must be False.

GBufferB encoding ​

GBufferB normally stores Metallic, Specular and Roughness. The GBufferB encoding packs Metallic and Specular into one channel, and stores the blend ID in the channel that frees up. Material AO and baked lighting are left untouched.

  • Packing - Non-metallic pixels store Specular in 7 bits, with the default Specular of 0.5 kept exact. Metallic pixels store Metallic in 7 bits and use the default Specular of 0.5. On the Substrate Blendable GBuffer they use 1.0, which matches what Substrate reports.

Applying the patches by hand ​

You can apply the patches yourself instead of using the Shader Patcher Tool, for example on a source-built engine.

Each patch is listed in MeshBlend/Source/MeshBlendEditor/Private/MeshBlendShaderPatcher.cpp, with a comment that shows the original engine code and the patched code:

cpp
/** Original/Patch
 * <original engine line>
 * --- Patched ---
 * <patched lines>
 */
  1. Find the original line in the engine shader file named by the patch
  2. Replace it with the patched lines
  3. Apply all patches for one encoding only, never a mix of both
  4. Update DefaultEngine.ini to match:
    • GBuffer AO - r.AllowStaticLighting=False and r.Lumen.ScreenProbeGather.MaterialAO=0
    • GBufferB - r.MeshBlend.IdStorage=1

NOTE

Copy the patched lines exactly, including any // MeshBlend comments. The Shader Patcher Tool looks for the exact patched lines to tell if a patch is applied.

Custom Setup ​

The plugin needs a single channel GBuffer texture to store data. The plugin doesn't care which one, and it has been made to be easily changed.

  1. Enable/Modify the GBuffer channel you want to use*

  2. Hook the MeshBlend material function up to the desired output instead of the Ambient Occlusion in your materials

  3. Update GetMeshBlendStencil(float2 UV) in MeshBlend\Shaders\MeshBlendTextures.usf to use the desired GBuffer channel

CAUTION*

This is an advanced way of setting it up, and will most likely require years of experience.
While this is supported by the plugin, setting it up is left to the user.